package cn.train.controler;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import cn.train.service.AddTrain;
@WebServlet("/AddTrainServlet")
public class AddTrainServlet extends HttpServlet {

	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		// TODO Auto-generated method stub
		String cname=req.getParameter("lcname");
		String rnrs=req.getParameter("rnrs");
		String kclx=req.getParameter("kclx");
		String qdz=req.getParameter("qdz");
		String zdz=req.getParameter("zdz");
		String cfsj=req.getParameter("cfsj");
		String dzsj=req.getParameter("dzsj");
		String cpjcj=req.getParameter("cpjcjq");
		
		AddTrain at=new AddTrain();
		if(!"".equals(cname)&cname!=null) {
		//System.out.println(cname+";"+rnrs+";"+kclx+";"+qdz+";"+zdz+";"+cfsj+";"+dzsj+";"+cpjcj);
			int flag=at.addtrain(cname,rnrs,kclx,qdz,zdz,cfsj,dzsj,cpjcj);
			if(flag==1) {
				req.setAttribute("flag", 1);
				req.getRequestDispatcher("back/addTrain.jsp").forward(req, resp);
				return;
			}
		}
			resp.sendRedirect("back/addTrain.jsp");
		    
	}
	
	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(req, resp);
	}

}
